<?php

namespace App\Models\OpenShop\InvestmentPromotion;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use DateTimeInterface;

class OpenShopSpaceDesignSoftLogisticsModel extends BaseModel
{
    use KfSoftDeletes;

    protected $table = 'open_shop_space_design_soft_logistics';

    protected $fillable = [
        'orderNo',
        'preparationNo',
        'type',
        'productName',
        'logisticsName',
        'logisticsNumber',
        'receiverName',
        'receiverNumber',
        'receiverArea',
        'receiverAddress',
        'isDeleted',
        'status',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
        'provinceCode',
        'cityCode',
        'areaCode',
        'sendNo',
        'expressEnName'
    ];

    protected $appends = [
        'typeText',
        'statusText',
        'receiveTimeDate'
    ];

    const TYPE_1 = 1;
    const TYPE_2 = 2;

    const CN_TYPE = [
        self::TYPE_1 => '大件物流',
        self::TYPE_2 => '快递单号',
    ];

    const STATUS_1 = 1;
    const STATUS_2 = 2;
    const STATUS_3 = 3;
    const STATUS_4 = 4;
    const STATUS_5 = 5;
    const STATUS_6 = 6;

    const CN_STATUS = [
        self::STATUS_1 => '未发货',
        self::STATUS_2 => '已发货',
        self::STATUS_3 => '运输中',
        self::STATUS_4 => '已到货',
        self::STATUS_5 => '已签收',
        self::STATUS_6 => '已退回',
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format("Y-m-d H:i:s");
    }

    public function getTypeTextAttribute()
    {
        return self::CN_TYPE[$this->type];
    }

    public function getStatusTextAttribute()
    {
        return self::CN_STATUS[$this->status];
    }

    public function getReceiveTimeDateAttribute()
    {
        return $this->receiveTime != 0 ? date('Y-m-d H:i:s', $this->receiveTime) : '';
    }

}
